import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
//配置参考来自https://blog.csdn.net/u014678583/article/details/116991796
//path用于配置目录别名
import path from 'path';
//以下3项用于按需导入element-plus
import AutoImport from 'unplugin-auto-import/vite';
import Components from 'unplugin-vue-components/vite';
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers';

//读取当前环境是否是生产环境
const isProduction = process.env.NODE_ENV === 'production';
export default defineConfig({
	base: '/', // 类似publicPath，'./'避免打包访问后空白页面，不加线上也访问不了
	//关闭生产环境下的SourceMap映射文件，true本地调试时可以定位到报错的ts，false用在生产环境可以减少打包的文件数
	productionSourceMap: !isProduction,
	plugins: [
		vue(),
		AutoImport({
			resolvers: [ElementPlusResolver()]
		}),
		Components({
			resolvers: [ElementPlusResolver()]
		})
	],
	resolve: {
		alias: {
			'@pub': path.resolve(__dirname, './public'),
			'@': path.resolve(__dirname, './src'),
			'@assets': path.resolve(__dirname, './src/assets'),
			'@images': path.resolve(__dirname, './src/assets/images'),
			'@components': path.resolve(__dirname, './src/components'),
			'@business': path.resolve(__dirname, './src/components/business'),
			'@views': path.resolve(__dirname, './src/views'),
			'@store': path.resolve(__dirname, './src/store'),
			'@util': path.resolve(__dirname, './src/util'),
			'@router': path.resolve(__dirname, './src/router')
		}
	},
	server: {
		https: false, // 是否开启 https
		port: 3000,
		host: '0.0.0.0',
		open: true, //服务器运行后自动打开网页
		cors: true, // 允许跨域  8月更新
		proxy: {
			'/authServer': {
				target: 'http://118.195.218.112:6815/', // 后台接口，对应Axios的BaseUrl要用/authServer/api替换
				//target: 'http://127.0.0.1:6815/', // 后台接口，对应Axios的BaseUrl要用/authServer/api替换
				changeOrigin: true,
				secure: false, // 如果是https接口，需要配置这个参数
				// ws: true, //websocket支持
				rewrite: url_path => url_path.replace(/^\/authServer/, '')
			},
			'/bussServer': {
				target: 'http://qb.sso.com:6677/', // 业务系统后台接口，对应Axios的BaseUrl要用/bussServer/api替换
				changeOrigin: true,
				secure: false, // 如果是https接口，需要配置这个参数
				// ws: true, //websocket支持
				rewrite: url_path => url_path.replace(/^\/bussServer/, '')
			},
			'/userServer': {
				target: 'http://www.fusegame.cn:2536/', // 后台接口
				changeOrigin: true,
				secure: false, // 如果是https接口，需要配置这个参数
				// ws: true, //websocket支持
				rewrite: url_path => url_path.replace(/^\/userServer/, '')
			},
			'/api': {
				target: 'http://qb.sso.com:6677', // 笔记访问代理
				changeOrigin: true,
				secure: false, // 如果是https接口，需要配置这个参数
				rewrite: (path) => path.replace(/^\/api/, '')
			}
		}
	}
});